package com.luge.model.share;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.luge.heart.R;
import com.luge.heart.ShareActivity;

public class Share {
	public static final int IMAGE = 1;
	public static final int MUSIC = 2;
	public static final int VEDIO = 3;

	private static final int SINA = 0;
	private static final int WEIXIN = 1;
	private Context context;

	public Share(Context context) {
		this.context = context;
	}

	public static ProgressDialog dialog = null;

	public static void shareTwitter(final Context context,
			final String ShareText, final String ShareUrl,
			final String filePath, final int type, final String imageURL) {
		final Dialog mDialog = new Dialog(context);
		mDialog.setCanceledOnTouchOutside(true);
		mDialog.setTitle(context.getString(R.string.share_to_str));

		LinearLayout layout = (LinearLayout) LayoutInflater.from(context)
				.inflate(R.layout.share_dialog, null);
		LinearLayout sinaLayout = (LinearLayout) layout
				.findViewById(R.id.share_sina_layout);
		sinaLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent sinaIntent = new Intent(context, ShareActivity.class);
				sinaIntent.putExtra("FileType", type);
				sinaIntent.putExtra("ShareText", ShareText);
				sinaIntent.putExtra("ShareUrl", ShareUrl);
				((Activity) context).startActivity(sinaIntent);
				mDialog.dismiss();
			}
		});
		LinearLayout weixinLayout = (LinearLayout) layout
				.findViewById(R.id.share_weixin_layout);
		weixinLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				WXShareAPI api = new WXShareAPI(context);
				api.createDialog(context, type, ShareText, "", filePath,
						imageURL);
				mDialog.dismiss();
			}
		});
		mDialog.setContentView(layout);
		mDialog.show();
	}

	public static void sendShareReceiver(Context context, int type) {
		Intent intent = new Intent(Constant.SHARE_RESULT);
		intent.putExtra("weiboType", type);
		context.sendBroadcast(intent);
	}

	public static void createDialog(Context context, String str) {
		dialog = new ProgressDialog(context);
		dialog.setCanceledOnTouchOutside(false);
		dialog.setMessage(str);
		dialog.show();
	}

	public static void clearDialog() {
		if (null != dialog) {
			dialog.dismiss();
		}
	}

}
